package com.health.webservices.dzjmjkkxml;

import java.io.StringReader;

import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;

import com.health.model.DZJMJKKXcrzBean;

import android.util.Log;
import android.util.Xml;

public class PullDZJMJKKXcrzParser implements DZJMJKKXcrzParser {
	@Override
	public DZJMJKKXcrzBean parse(String xmlData) throws Exception {
		DZJMJKKXcrzBean ecg = null;

		// XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
		// XmlPullParser parser = factory.newPullParser();

		XmlPullParser parser = Xml.newPullParser(); // 由android.util.Xml创建一个XmlPullParser实例
		// parser.setInput(is, "UTF-8"); // 设置输入流 并指明编码方式
		try {
			parser.setInput(new StringReader(xmlData));
		} catch (XmlPullParserException e) {
			e.printStackTrace();
		}

		int eventType = parser.getEventType();
		while (eventType != XmlPullParser.END_DOCUMENT) {
			String nodeName = parser.getName();
			switch (eventType) {
			case XmlPullParser.START_DOCUMENT:
				ecg = new DZJMJKKXcrzBean();
				break;
			case XmlPullParser.START_TAG:
				Log.w("eeeeeepull解析------", "ee" + parser.getName());
				// <response><result>success</result>
				// <desc>注册成功</desc><personinfo>
				// <name>刘1</name><main_index>420300201712131111240021770</main_index>
				// <telephone>13406952363</telephone><id_number>420300199111114381</id_number>

				if ("result".equals(nodeName)) {
					eventType = parser.next();
					ecg.setResult(parser.getText());

				} else if ("desc".equals(nodeName)) {
					eventType = parser.next();
					ecg.setDesc(parser.getText());

				} else if ("name".equals(nodeName)) {
					eventType = parser.next();
					ecg.setName(parser.getText());

				} else if ("main_index".equals(nodeName)) {
					eventType = parser.next();
					ecg.setMain_index(parser.getText());

				} else if ("telephone".equals(nodeName)) {
					eventType = parser.next();
					ecg.setTelephone(parser.getText());

				} else if ("id_number".equals(nodeName)) {
					eventType = parser.next();
					ecg.setId_card(parser.getText());
					// <id_type>01</id_type><id_card>420300199111114381</id_card>
					// <nation>01</nation>
					// <sex>2</sex><birthday>19911111</birthday><address>济南西站</address>
					// <ehc_card_status>2</ehc_card_status></personinfo></response>

				} else if ("id_type".equals(nodeName)) {
					eventType = parser.next();
					ecg.setId_type(parser.getText());

				} else if ("id_card".equals(nodeName)) {
					eventType = parser.next();
					ecg.setId_card(parser.getText());

				} else if ("nation".equals(nodeName)) {
					eventType = parser.next();
					ecg.setNation(parser.getText());// 01-56

				} else if ("sex".equals(nodeName)) {
					eventType = parser.next();
					ecg.setSex(parser.getText());// 0、1、2、9

				} else if ("birthday".equals(nodeName)) {
					eventType = parser.next();
					ecg.setBirthday(parser.getText());// 19911111

				} else if ("address".equals(nodeName)) {
					eventType = parser.next();
					ecg.setAddress(parser.getText());

				} else if ("ehc_card_status".equals(nodeName)) {
					eventType = parser.next();
					ecg.setEhc_card_status(parser.getText());

				}
			case XmlPullParser.END_TAG:
				if ("response".equals(nodeName)) {
					Log.w("eeeeeeeeee000000", ecg.toString());

				}
				break;
			}
			eventType = parser.next();
		}
		return ecg;
	}

	@Override
	public String serialize(DZJMJKKXcrzBean ecg) throws Exception {
		// TODO Auto-generated method stub
		return null;
	}

}
